<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="圈子名称" prop="circName">
        <el-input
            v-model="queryParams.circName"
            placeholder="请输入创建名称"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="举报人昵称" prop="nickName">
        <el-input
            v-model="queryParams.nickName"
            placeholder="请输入创建名称"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="举报类型" prop="type" style="width:15%">-->
<!--        <el-select v-model="queryParams.type" placeholder="请选择举报类型" clearable>-->
<!--          <el-option-->
<!--            v-for="dict in report_type"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="reportList" @selection-change="handleSelectionChange">
      <el-table-column label="举报人" align="center" prop="nickName" />
      <el-table-column label="圈子名称" align="center" prop="name" />
      <el-table-column label="举报帖子" align="center" prop="content" />
      <el-table-column label="举报时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
<!--          <el-button link type="primary" icon="View" @click="handleView(scope.row)" v-hasPermi="['main:report:view']">查看详情</el-button>-->
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['main:report:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />

    <!-- 添加或修改举报记录对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="reportRef" :model="form" :rules="rules" label-width="100px">
      <el-form-item label="举报类型" prop="type">
        <el-select v-model="form.type" disabled placeholder="请选择(0圈子 1动态 2个人)">
          <el-option
              v-for="dict in report_type"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="业务id" prop="businessId">
        <el-input v-model="form.businessId" disabled placeholder="请输入业务id" />
      </el-form-item>
      <el-form-item label="备注" prop="memo">
        <el-input v-model="form.memo" disabled placeholder="请输入备注" />
      </el-form-item>
<!--      <el-form-item label="是否删除;0否1是" prop="delFlag">-->
<!--        <el-input v-model="form.delFlag" placeholder="请输入是否删除;0否1是" />-->
<!--      </el-form-item>-->
      <el-form-item label="创建人" prop="createUser">
        <el-input v-model="form.createUser" disabled placeholder="请输入创建人" />
      </el-form-item>
      <el-form-item label="创建人名称" prop="createName">
        <el-input v-model="form.createName" disabled placeholder="请输入创建名称" />
      </el-form-item>
      <el-form-item label="更新人" prop="updateUser">
        <el-input v-model="form.updateUser" disabled placeholder="请输入更新人" />
      </el-form-item>
      <el-form-item label="更新人名称" prop="updateName">
        <el-input v-model="form.updateName" disabled placeholder="请输入更新名称" />
      </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
<!--          <el-button type="primary" @click="submitForm">确 定</el-button>-->
          <el-button @click="cancel">关 闭</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Report">
  import { listReport, getReport, delReport, addReport, updateReport } from "@/api/main/report";

  const { proxy } = getCurrentInstance();
  const { report_type } = proxy.useDict('report_type');
const router=useRouter();
  const reportList = ref([]);
  const open = ref(false);
  const loading = ref(true);
  const showSearch = ref(true);
  const ids = ref([]);
  const single = ref(true);
  const multiple = ref(true);
  const total = ref(0);
  const title = ref("");

  const data = reactive({
    form: {},
    queryParams: {
      pageNum: 1,
      pageSize: 10,
      // type: null,
      // businessId: null,
      // memo: null,
      // status: null,
      circName:"",
      nickName:""
    },
    rules: {
      // status: [
      //   { required: true, message: "状态不能为空", trigger: "change" }
      // ],
      // delFlag: [
      //   { required: true, message: "是否删除;0否1是不能为空", trigger: "blur" }
      // ],
    }
  });

  const { queryParams, form, rules } = toRefs(data);

  /** 查询举报记录列表 */
  function getList() {
    loading.value = true;
    listReport(queryParams.value).then(response => {
      reportList.value = response.rows;
      total.value = response.total;
      loading.value = false;
    });
  }

  // 取消按钮
  function cancel() {
    open.value = false;
    reset();
  }

  // 表单重置
  function reset() {
    form.value = {
      id: null,
      type: null,
      businessId: null,
      memo: null,
      status: null,
      delFlag: null,
      createUser: null,
      createName: null,
      createTime: null,
      updateUser: null,
      updateName: null,
      updateTime: null
    };
    proxy.resetForm("reportRef");
  }

  /** 搜索按钮操作 */
  function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
  }

  /** 重置按钮操作 */
  function resetQuery() {
    proxy.resetForm("queryRef");
    handleQuery();
  }

  // 多选框选中数据
  function handleSelectionChange(selection) {
    ids.value = selection.map(item => item.id);
    single.value = selection.length != 1;
    multiple.value = !selection.length;
  }

  /** 新增按钮操作 */
  function handleAdd() {
    reset();
    open.value = true;
    title.value = "添加举报记录";
  }

  /** 修改按钮操作 */
  function handleUpdate(row) {
    reset();
    const _id = row.id || ids.value
    getReport(_id).then(response => {
      form.value = response.data;
      open.value = true;
      title.value = "修改举报记录";
    });
  }

  function handleView(row){
    getReport(row.id).then(response => {
      title.value = "查看举报记录";
      form.value = response.data;
      open.value = true;
    });
    // router.push({path: '/treads/'+row.id});
    open.value=true;
    return

    if(row.type==0){
      router.push({path: '/circle/'+row.id});
    }else if(row.type==1){

    }else{
      router.push({path: '/member/'+row.id});
    }
  }

  /** 提交按钮 */
  function submitForm() {
    proxy.$refs["reportRef"].validate(valid => {
      if (valid) {
        if (form.value.id != null) {
          updateReport(form.value).then(response => {
            proxy.$modal.msgSuccess("修改成功");
            open.value = false;
            getList();
          });
        } else {
          addReport(form.value).then(response => {
            proxy.$modal.msgSuccess("新增成功");
            open.value = false;
            getList();
          });
        }
      }
    });
  }

  /** 删除按钮操作 */
  function handleDelete(row) {
    const _ids = row.id;
    proxy.$modal.confirm('是否确认删除举报记录编号为"' + _ids + '"的数据项？').then(function() {
      return delReport(_ids);
    }).then(() => {
      getList();
      proxy.$modal.msgSuccess("删除成功");
    }).catch(() => {});
  }

  /** 导出按钮操作 */
  function handleExport() {
    proxy.download('main/report/export', {
      ...queryParams.value
    }, `report_${new Date().getTime()}.xlsx`)
  }

  getList();
</script>
